// import app from './modules/app'
// import user from './modules/user'
// import permission from './modules/permission'
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import mutations from './mutations'
import actions from './actions'
import errorHandle from './modules/errorHandle'
import Cookies from 'js-cookie'

Vue.use(Vuex)

let currentToken = Cookies.get('token')
let currentUser = {
  userId: '',
  loginName: '',
  mobile: '',
  email: '',
  realName: '',
  headIco: '',
  companyName: '',
  legaler: '',
  status: '',
  parentUser: '',
  role: [], // 用户角色
  permission: [] // 用户权限
}
if (sessionStorage.getItem('currentUser')) {
  currentUser = JSON.parse(sessionStorage.getItem('currentUser'))
}

let state = {
  // 当前用户
  currentUser: currentUser,
  currentToken: currentToken, // 当前token
  activeMenu: '' // 当前活动导航
}

let debug = process.env.NODE_ENV !== 'production'

const store = new Vuex.Store({
  modules: {
    errorHandle
  },
  state,
  getters,
  mutations,
  actions,
  strict: debug
})

// store.watch(
//   (state) => state.chat.sessions,
//   (val) => {
//     console.log('CHANGE: ', val)
//     localStorage.setItem('vue-chat-session', JSON.stringify(val))
//   },
//   {
//     deep: true
//   }
// )

export default store
